package com.platform.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.platform.dao.GoodsSpecificationDao;
import com.platform.entity.GoodsSpecificationEntity;

/**
 * 商品对应规格表值表Service接口
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2017-08-31 11:15:55
 */
@Service("goodsSpecificationService")
public class GoodsSpecificationService {
	
    @Autowired
    private GoodsSpecificationDao goodsSpecificationDao;
    
    public Map<Integer,List<GoodsSpecificationEntity>> getGoodsSpecificationsMap(Integer goodsId){
    	Map<String, Object> params = new HashMap<>();
        params.put("goodsId", goodsId);
        List<GoodsSpecificationEntity> list = goodsSpecificationDao.queryList(params);
        Map<Integer,List<GoodsSpecificationEntity>> specificationMap = new HashMap<Integer,List<GoodsSpecificationEntity>>();
        
        for(GoodsSpecificationEntity goodsSpecification:list) {
        	List<GoodsSpecificationEntity> singleList = specificationMap.get(goodsSpecification.getSpecificationId());
        	if(singleList == null) {
        		singleList = new ArrayList<GoodsSpecificationEntity>();
        		specificationMap.put(goodsSpecification.getSpecificationId(), singleList);
        	}
        	singleList.add(goodsSpecification);
        }
        return specificationMap;
    }

    public Collection<List<GoodsSpecificationEntity>> getGoodsSpecificationsList(Integer goodsId){
    	Map<String, Object> params = new HashMap<>();
        params.put("goodsId", goodsId);
        List<GoodsSpecificationEntity> list = goodsSpecificationDao.queryList(params);
        Map<Integer,List<GoodsSpecificationEntity>> specificationMap = new HashMap<Integer,List<GoodsSpecificationEntity>>();
        
        for(GoodsSpecificationEntity goodsSpecification:list) {
        	List<GoodsSpecificationEntity> singleList = specificationMap.get(goodsSpecification.getSpecificationId());
        	if(singleList == null) {
        		singleList = new ArrayList<GoodsSpecificationEntity>();
        		specificationMap.put(goodsSpecification.getSpecificationId(), singleList);
        	}
        	singleList.add(goodsSpecification);
        }
        return specificationMap.values();
    }
    
    public GoodsSpecificationEntity queryObject(Integer id) {
        return goodsSpecificationDao.queryObject(id);
    }

    public List<GoodsSpecificationEntity> queryList(Map<String, Object> map) {
        return goodsSpecificationDao.queryList(map);
    }

    public int queryTotal(Map<String, Object> map) {
        return goodsSpecificationDao.queryTotal(map);
    }

    public int save(GoodsSpecificationEntity goodsSpecification) {
        return goodsSpecificationDao.save(goodsSpecification);
    }

    public int update(GoodsSpecificationEntity goodsSpecification) {
        return goodsSpecificationDao.update(goodsSpecification);
    }

    public int delete(Integer id) {
        return goodsSpecificationDao.delete(id);
    }

    public int deleteBatch(Integer[]ids) {
        return goodsSpecificationDao.deleteBatch(ids);
    }
}
